package com.cuit.zuke.hotel.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cuit.zuke.hotel.mapper.HotelSetMapper;
import com.cuit.zuke.hotel.service.HotelSetService;
import com.cuit.zuke.common.exception.GlobalException;
import com.cuit.zuke.hotel.model.hotel.HotelSet;
import org.springframework.stereotype.Service;

@Service
public class HotelSetServiceImpl extends ServiceImpl<HotelSetMapper, HotelSet> implements HotelSetService {

    /**
     * 根据酒店编号获取签名密钥
     * @param zkcode 酒店编号
     * @return 签名密钥
     */
    @Override
    public String getSignKey(String zkcode) {
        HotelSet hotelSet = this.getByzkcode(zkcode);

        if(null == hotelSet ) {
            throw new GlobalException("该酒店设置不存在");
        }
        if(hotelSet.getStatus().intValue() == 0) {
            throw new GlobalException("该酒店设置已被锁定");
        }
        return hotelSet.getSignKey();
    }

    /**
     * 根据zkcode获取酒店设置
     * @param zkcode 酒店编号
     * @return 酒店设置数据
     */
    private HotelSet getByzkcode(String zkcode) {
        return baseMapper.selectOne(new QueryWrapper<HotelSet>().eq("zkcode", zkcode));
    }


}
